using System;
using System.Web.UI;

using Impact.Views;
using Impact.Web.Foundation;

namespace Impact.Web
{
    /// <summary>
    /// code-behind for the default view presenting dynamic content
    /// </summary>
    public partial class Default : Impact.Web.Foundation.PageBase, Impact.Views.IContentView
    {

        private Control view;

        #region IContentView Members

        /// <summary>
        /// creates the control referenced by userControlSource, and if it is a
        /// IContentControl, sets the dataSource on the control.  then adds
        /// the control to the display.
        /// </summary>
        /// <remarks>called during Page.OnInit</remarks>

        public void ContentInit(string userControlSource, object dataSource)
        {
            this.view = this.LoadControl(userControlSource);
            if (view is IContentControl)
            {
                (view as IContentControl).DataSource = dataSource;
            }

        }

        /// <summary>
        /// rendering of controls is performed on the view
        /// </summary>
        /// <remarks>called during Page.OnLoad</remarks>
        public void ContentRender()
        {
            if (view != null)
            {
                this._bodyPlaceholder.Controls.Add(view);
            }
        }

        /// <summary>
        /// fired before the OnInit event, to signal to the view to perform its PreInit tasks
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreInit(EventArgs e)
        {
            base.OnPreInit(e);

            if (view is IContentControl)
            {
                (view as IContentControl).PreInit();
            }


        }

        #endregion


    }
}
